package com.qf.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.Goods;
import com.qf.entity.GoodsEntity;
import com.qf.entity.Stock;
import com.qf.mapper.GoodsMapper;
import com.qf.mapper.StockMapper;
import com.qf.service.GoodsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper,GoodsEntity> implements GoodsService {
  @Autowired
   private StockMapper stockMapper;
    @Override
    @Transactional
    public boolean saveGoodsAndStock(Goods goods) {
        //插入商品信息
        GoodsEntity entity = new GoodsEntity();
        BeanUtils.copyProperties(goods,entity);
        super.save(entity);
        System.out.println("之前:"+goods.getId());
        goods.setId(entity.getId());
        System.out.println("之后"+goods.getId());
        //插入库存
        Stock stock = new Stock();
        stock.setGid(entity.getId());
        stock.setStock(entity.getStock());
        stockMapper.insert(stock);

        return true;
    }
}